package com.test3;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MyTest_03 {

    @Test
    public void test1() {
        List<Integer> list = Arrays.asList(15, 28, 31, 19);
        System.out.println(list);
        // Arrays.asList()返回的集合，不能调用集合中的方法，否则会抛异常
        // fromArrayToList(list, 63, 24, 55);
        list = fromArrayToList2(list, 63, 24, 55);
        System.out.println(list);
    }

    /** 泛型方法 */
    public static <T> void fromArrayToList(List<T> list, T... array) {
        if (list != null && array != null) {
            for (T t : array) {
                list.add(t);
            }
        }
    }

    public static <T> List<T> fromArrayToList2(List<T> list, T... array) {
        List<T> result = null;
        if (list != null && array != null) {
            result = new ArrayList<>();
            result.addAll(list);
            for (T t : array) {
                result.add(t);
            }
        }
        return result;
    }
}
